home *** CD-ROM | disk | FTP | other *** search
- /* Code from Kaypro Column in Micro Cornucopia Magazine Issue #41
- * COUNT -- Counts characters, words, and lines in input
- *
- * Written for Small-C compiler vers. 2.03 (ASM)
- *
- */
-
- #include <stdioa.h>
- #include "iolib.asm"
- #include "call.asm"
-
- #define NOCCARGC
- #define HIGHBIT 127 /* high bit mask = 01111111b */
-
- int infile;
- char fname[15];
-
- main (argc, argv) int argc, argv[]; {
-
- char *lines, *words, *chars; /* fake unsigned integers */
- int inword, c;
- fputs("COUNT vers. 8/24/87\n",stderr);
- if (argc >= 2)
- infile = fopen(argv[1],"r");
- else {
- fputs("Counts words, lines and chars in text file.\n",stderr);
- fputs("Name of file to check: ? ",stderr);
- gets(fname);
- infile = fopen(fname,"r");
- }
-
- if (infile == NULL) {
- fputs("File not found.",stderr);
- exit();
- }
-
- fputs("Processing file...",stderr);
- inword = NO;
- lines = words = chars = 0;
- while ((c = getc(infile)) != EOF) {
- ++chars;
- c &= HIGHBIT; /* mask high bit for WordStar files */
- if (c == '\n')
- ++lines;
- if (c==' ' || c=='\n' || c=='\t')
- inword = NO;
- else if (inword == NO) {
- inword = YES;
- ++words;
- }
- }
- fputc('\n',stderr);
- fputs("Chars = ",stderr);
- putnum(chars,stderr);
- fputc('\n',stderr);
- fputs("Words = ",stderr);
- putnum(words,stderr);
- fputc('\n',stderr);
- fputs("Lines = ",stderr);
- putnum(lines,stderr);
- fputc('\n',stderr);
- }
-
- /*
- * write unsigned number n to fd as string.
- */
- putnum(n,fd) char *n; int fd; {
- char numstr[7];
- fputs(itou(n,numstr,6),fd);
- }
-
- #include "itou.c"